const webpack = require('webpack')
const { merge } = require('webpack-merge')
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const webpackCommon = require('./webpack.common.js')

module.exports = merge(webpackCommon, {
    mode: 'production',
    plugins: [
        new CleanWebpackPlugin(),
        new CopyWebpackPlugin({
            patterns: [{
                from: 'public'
            }]
        })
    ],
    optimization: {
        minimizer: [
            new OptimizeCssAssetsWebpackPlugin(),
            new TerserWebpackPlugin()
        ],
        splitChunks: {
            chunks: 'all'   
        },
        usedExports: true,
        concatenateModules: true,
        minimize: true
    }
})